package ar.edu.utn.frba.dds.tp.ui;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.windows.MainWindow;

import uqbar.arena.persistence.Configuration;
import ar.edu.utn.frba.dds.tp.code.usuarios.UsuarioStandard;
import ar.edu.utn.frba.dds.tp.ui.appModel.BusquedasManager;
import ar.edu.utn.frba.dds.tp.ui.appModel.ComprasManager;
import ar.edu.utn.frba.dds.tp.ui.appModel.ReservasManager;

@SuppressWarnings("serial")
public class PrincipalWindow extends MainWindow<UsuarioStandard> {

	public PrincipalWindow() {
		super(new UsuarioStandardMock());
	}

	@Override
	public void createContents(Panel mainPanel) {
		
		this.setTitle("Aterrizar.Com");
		mainPanel.setLayout(new VerticalLayout());
		
		this.buildSaludo(mainPanel);

		new Label(new Panel(mainPanel).setLayout(new HorizontalLayout()))
			.setText("¿Que desea hacer?");
		this.buildBotonera(mainPanel);
	}

	private void buildSaludo(Panel mainPanel) {
		Panel saludo = new Panel(mainPanel);
		saludo.setLayout(new HorizontalLayout());
				
		new Label(saludo).setText("Hola, ");
		new Label(saludo).bindValueToProperty("nombre");
	}
	
	
	private void buildBotonera(Panel mainPanel) {
		Panel botonera = new Panel(mainPanel);
		botonera.setLayout(new HorizontalLayout());
		
		new Button(botonera)
			.setCaption("Ver Compras")
			.onClick(new MessageSend(this, "verCompras"));
		new Button(botonera)
			.setCaption("Ver Reservas")
			.onClick(new MessageSend(this, "verReservas"));
		new Button(botonera)
			.setCaption("Buscar Asientos")
			.onClick(new MessageSend(this,"BuscarAsientos"));

	}

	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//+++ MAIN +++++++++++++++++++++++++++++++++++++++++++++++++++
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	public static void main(String[] args) {
		Configuration.configure();
		
		new PrincipalWindow().startApplication();
	}
	
	public void BuscarAsientos(){
		new BuscarWindow(getOwner(), new BusquedasManager(), this.getModelObject()).open();
	}
	
	public void verCompras() {
		new TransaccionesWindow(getOwner(), new ComprasManager(), this.getModelObject(), "Compras de ").open();
	}
	
	public void verReservas() {
		new TransaccionesWindow(getOwner(), new ReservasManager(), this.getModelObject(), "Reservas de ").open();
	}

}
